package com.zy.web.controller.bs;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.zy.entity.bs.Msg;
import com.zy.pojo.query.bs.MsgQuery;
import com.zy.pojo.vos.common.PageVo;
import com.zy.pojo.vos.common.ResultVo;
import com.zy.service.bs.MsgService;
import com.zy.web.controller.base.BaseController;
import com.zy.web.utils.ResultUtil;

@RequestMapping({"bs/msg","m/bs/msg"})
@Controller
public class MsgController extends BaseController {

	@Autowired
	private MsgService msgService;

	/**
	 * 分页
 	 * 
 	 * @param msgQuery
	 * @param start
	 * @param limit
	 * @return
	 */
	@RequestMapping("pageMsg")
	@ResponseBody
	public PageVo pageMsg(MsgQuery msgQuery, Integer start, Integer limit) {
		return this.msgService.pageMsg(msgQuery, start, limit);
	}

	/**
	 * 新增
	 * 
	 * @param msg
	 * @return
	 */
	@RequestMapping(value = "saveMsg", method = RequestMethod.POST)
	@ResponseBody
	public ResultVo saveMsg(Msg msg) {
		try {
			this.msgService.saveMsg(msg);
			return ResultUtil.success();
		} catch (Exception e) {
			return ResultUtil.error(log, e);
		}
	}
	
	/**
	 * 更新
	 * 
	 * @param msg
	 * @return
	 */
	@RequestMapping(value = "updateMsg", method = RequestMethod.POST)
	@ResponseBody
	public ResultVo updateMsg(Msg msg) {
		try {
			this.msgService.updateMsg(msg);
			return ResultUtil.success();
		} catch (Exception e) {
			return ResultUtil.error(log, e);
		}
	}

	/**
	 * 删除
	 * 
	 * @param id
	 * @return
	 */
	@RequestMapping(value = "removeMsg", method = RequestMethod.POST)
	@ResponseBody
	public ResultVo removeMsg(long id) {
		try {
			this.msgService.removeMsg(id);
			return ResultUtil.success();
		} catch (Exception e) {
			return ResultUtil.error(log, e);
		}
	}

	/**
	 * 恢复
	 * 
	 * @param id
	 * @return
	 */
	@RequestMapping(value = "recover", method = RequestMethod.POST)
	@ResponseBody
	public ResultVo recover(long id) {
		try {
			this.msgService.recover(id);
			return ResultUtil.success();
		} catch (Exception e) {
			return ResultUtil.error(log, e);
		}
	}

	@RequestMapping("appListMsg")
	@ResponseBody
	public PageVo appListMsg(MsgQuery msgQuery, Integer start, Integer limit) {
		msgQuery.setSendCustomerId(this.getCurrentCustomer().getId());
		msgQuery.setHandlerCustomerId(this.getCurrentCustomer().getId());
		return this.msgService.appListMsg(msgQuery, start, limit);
	}

	@RequestMapping("getMsgInfo")
	@ResponseBody
	public ResultVo getMsgInfo(Long id) {
		try {
			return ResultUtil.success(this.msgService.getByPrimaryKey(id));
		} catch (Exception e) {
			return ResultUtil.error(log, e);
		}
	}

}